home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12301 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  51 lines

  1. Path: EU.net!sun4nl!xs4all!jordan
  2. From: jordan@xs4all.nl (Jordan)
  3. Newsgroups: comp.lang.c
  4. Subject: Returning string from function (how?)
  5. Date: 30 Mar 1996 11:05:21 GMT
  6. Organization: XS4ALL Internet
  7. Message-ID: <4jj4hh$m9n@news.xs4all.nl>
  8. NNTP-Posting-Host: xs1.xs4all.nl
  9.  
  10. Hi all, i'm trying to get a string returned  from a function, but it's not
  11. working as i planed.
  12. Does anyone have some ideas?
  13.  
  14.  
  15. something like this, but then working ;)
  16.  
  17. /*****************************************/
  18.  
  19. char s;
  20.  
  21. char get_str(void);
  22.  
  23. main()
  24. {
  25.    s = get_str();
  26.  
  27.    printf("%s", s);
  28. }
  29.  
  30. char get_str(void)
  31. {
  32.    int i;
  33.    char ch, string;
  34.  
  35.    i=0;    
  36.    printf("Enter a string: ");
  37.    while((ch = getchar()) != '\n' && i < MAX)
  38.       string[i++] = ch;
  39.    string[i] = '\0';
  40.  
  41.    return string;
  42. }
  43.  
  44.  
  45. Grtz Jordan
  46. --
  47. ---------------------------------------------jordan@dark4ce.xs4all.nl
  48. But what if you are lost on the Information Superhighway
  49.             who do you ask for directions... (J.G. - Future Quest)
  50. ---------------------------------------------------------------------
  51.